import { createSSRApp } from 'vue'
import { createI18n } from 'vue-i18n'
import App from './App.vue'
import enUS from './locale/en.json'
import zhCN from './locale/zh-Hans.json'
import thTH from './locale/th-TH.json'
import viVN from './locale/vi-VN.json'

// 导入 pinia 实例
import pinia, { useMemberStore } from './stores'
App.mpType = 'app'
export function createApp() {
  // 创建 vue 实例
  const app = createSSRApp(App)
  // 使用 pinia
  app.use(pinia)

  const memberStore = useMemberStore()
  // console.log('memberStore - - - > init 页面', memberStore)
  const i18n = createI18n({
    legacy: false,
    locale: memberStore.language || 'zh_CN',
    fallbackLocale: memberStore.language || 'zh_CN',
    messages: {
      zh_CN: zhCN,
      en_US: enUS,
      th_TH: thTH,
      vi_VN: viVN,
    },
  })
  //const { t,locale } = useI18n({ useScope: 'global' })
  // 使用i18n
  app.use(i18n)

  return {
    app,
  }
}
